<?php

/**
 * ContactForm class.
 * ContactForm is the data structure for keeping
 * contact form data. It is used by the 'contact' action of 'SiteController'.
 */
class Budget extends ActiveRecord
{
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
	
	public function tableName()
	{
		return 'vh_budget';
	}
	
	public function rules()
	{
		return array(
		);
	}

	public function getList($hyipId)
	{			
		$query = "SELECT t.*, domain
                FROM vh_budget t 
                JOIN vh_monitor m ON m.id = t.monitorId
                WHERE t.hyipID = $hyipId";
		
		$result = $this -> executeAllTotal($query, array(), true, "t.createdDate DESC");
	
		return $result;
	}    

	public function search()
	{
		$condition = "";
		
		if(!empty($_POST['monitor']))
			$condition .= " AND t.monitorId = " . $_POST['monitor'];
		
		if(!empty($_POST['hyip']))
			$condition .= " AND t.hyipId = " . $_POST['hyip'];
		
		if(!empty($_POST['startDate']) && !empty($_POST['endDate']))
			$condition .= " AND t.startDate <= '" . $_POST['endDate'] . "' AND t.endDate >= '" . $_POST['startDate'] . "'";
		else if(!empty($_POST['startDate']))
			$condition .= " AND t.startDate >= '" . $_POST['startDate'] . "'";
		else if(!empty($_POST['endDate']))
			$condition .= " AND t.endDate <= '" . $_POST['endDate'] . "'";
		
		$query = "SELECT t.*, m.domain as monitor, h.domain as hyip
                FROM vh_budget t 
                JOIN vh_monitor m ON m.id = t.monitorId
				JOIN vh_hyip h ON h.id = t.hyipId
				WHERE 1=1 $condition
        ";						
		
		$result = $this -> executeAllTotal($query, array(), true, "t.createdDate DESC");
	
		return $result;
	}
}